// 验证用户
const checkUser = async (ctx, next) => {
  if (ctx.params.id !== ctx.state.user._id) {
    ctx.throw(403, '没有权限')
  }
  await next()
}

// 验证提问者
const checkQuestioner = async (ctx, next) => {
  if (ctx.state.question.questioner._id.toString() !== ctx.state.user._id) {
    ctx.throw(403, '没有权限')
  }
  await next()
}

// 验证回答者
const checkAnswerer = async (ctx, next) => {
  if (ctx.state.answer.answerer._id.toString() !== ctx.state.user._id) {
    ctx.throw(403, '没有权限')
  }
  await next()
}

// 验证评论者
const checkCommentator = async (ctx, next) => {
  if (ctx.state.comment.commentator._id.toString() !== ctx.state.user._id) {
    ctx.throw(403, '没有权限')
  }
  await next()
}

module.exports = { checkUser, checkQuestioner, checkAnswerer, checkCommentator }
